CUBE CONNECT Edition Help

Connecting to a CUBE Database with the CubeDatabase class

When working with CUBE databases, the CubeDatabase class needs to be used. We call an instance of the class, so that a connection to a datastore is opened within CubeDatabase. The class will "register" the datastore as a CubeDatabase object, and this registration creates metadata within the datastore for use by the CubeAPI.

source_db = "input/cube7_networks/Cubetown.SQLite"
db = cp.CubeDatabase(source_db, False)

The first argument is the connection string with path and name of the CUBE database, whilst the second argument is the Boolean "create". When create=False, the database will not be created is it does not exist. In case the source_db is not a valid path, the "Connection failed" error will be returned. "False" is the default.

Several methods are now available to investigate and manipulate the data stored in the database. For example, the below statement will return a tuple with the network names stored in the CUBE database (instance called "db" above).

network_names = db.networkNames()

Returning a Python tuple like the below, for an example with two networks.

('net_name_1', 'net_name_2')

The items in the list of network names can be extracted from their index, for example, the first one is extracted and stored in a new variable called "first_network_name" as below.

first_network_name = network_names[0]